const { src, dest, watch } = require('gulp');
const less = require('gulp-less');
const rename = require('gulp-rename');
const plumber = require('gulp-plumber');

// 测试
function test(cb) { console.log('Hello gulp'); cb(); }

// less 解析
const goless = function () {
    return src('pages/**/*.less')
        .pipe(plumber())  // less自动编译防中断
        .pipe(less())
        .pipe(rename({ extname: '.wxss' }))
        .pipe(dest('pages/'));
}
// 自动监控
const autoless = function () { return watch('pages/**/*.less', goless); }

/**
 *  运行命令
 *  gulp 自动监控less
 *  gulp test 测试
 *  gulp goless 编译less
 */

exports.test = test
exports.goless = goless
exports.default = autoless